package site.wtcc.originalfavor.core.domain;

import lombok.Builder;
import lombok.Data;
import site.wtcc.originalfavor.func.annotation.AgeCheck;

import java.io.*;

/**
 * @author user
 */
@Data
@Builder
public class Student implements Serializable {

    private String user_id;
    private String user_name;
    private String id;
    private String age;

    @AgeCheck(20)
    private Integer year;

    private String name;

    public Major major;

    @Override
    public Student clone(){
        try {
            // 将对象本身序列化到字节流
            ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
            ObjectOutputStream objectOutputStream =
                    new ObjectOutputStream( byteArrayOutputStream );
            objectOutputStream.writeObject( this );

            // 再将字节流通过反序列化方式得到对象副本
            ObjectInputStream objectInputStream =
                    new ObjectInputStream( new ByteArrayInputStream( byteArrayOutputStream.toByteArray() ) );
            return (Student) objectInputStream.readObject();

        } catch (IOException | ClassNotFoundException e) {
            e.printStackTrace();
        }
        return null;
    }
}
